package com.hpu.service;

import java.util.ArrayList;
import java.util.List;

import com.hpu.dao.UserCommentDao;
import com.hpu.dao.UserDao;
import com.hpu.entity.User;
import com.hpu.entity.User_Comment;

public class UserService {

	UserDao userDao = new UserDao();
	UserCommentDao commentDao = new UserCommentDao();
	
	public void saveUser(User user){
		userDao.saveUser(user);
	}
	public User findByNamePassword(String name,String password){
		return userDao.findByNamePassword(name, password);
	}
	public List<User> findAllUsers(){
		List<User> userList = userDao.findAllUsers();
		List<User_Comment> commentList = commentDao.findAll();
		
		List<User> users = new ArrayList<User>();
		
		for (User user : userList) {
			List<User_Comment> list = new ArrayList<User_Comment>();
			for (User_Comment user_Comment : commentList) {
				if (user.getId().equals(user_Comment.getUser_id())) {
					System.out.println("USER:"+user.getId());
					System.out.println("COMMENT:"+user_Comment.getUser_id());
					list.add(user_Comment);
				}
			}
			user.setCommentList(list);
			users.add(user);
		}
		return users;
		
	}
}
